package hanxx.security.dao;

import hanxx.system.dao.BaseDao;
import hanxx.security.domain.SysRoleMenu;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.io.Serializable;
import java.util.List;

/**
 * 角色与菜单关联表 数据层
 *
 * @author ishangu.platform
 */
public interface SysRoleMenuDao extends BaseDao<SysRoleMenu, Serializable> {
    /**
     * 查询菜单使用数量
     *
     * @param menuId 菜单ID
     * @return 结果
     */

    @Query(value = " select count(1) from sys_role_menu where menu_id =?1 ", nativeQuery = true)
    public int checkMenuExistRole(Long menuId);

    /**
     * 通过角色ID删除角色和菜单关联
     *
     * @param roleId 角色ID
     * @return 结果
     */
    @Query(value = " delete from sys_role_menu where role_id =?1 ", nativeQuery = true)
    @Modifying
    public int deleteRoleMenuByRoleId(Long roleId);

    @Query(value = " delete from sys_role_menu where role_id in (?1) ", nativeQuery = true)
    @Modifying
    public int deleteRoleMenuByRoleIds(Long [] roleId);

    @Query(value = " select menu_id from sys_role_menu where role_id =?1 ", nativeQuery = true)
    public List<Long> listMenuIdByRoleId(Long roleId);

}
